package info.wangyuan.agent.controller.admin;


import info.wangyuan.agent.entity.po.ProviderConfig;
import info.wangyuan.agent.service.curd.ProviderService;
import info.wangyuan.agent.utils.Result;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务商配置管理
 *
 * @author Albert
 * @since 2025-09-04 22:19:42
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/provider")
public class ProviderController {

    private final ProviderService providerService;

    public ProviderController(ProviderService providerService) {
        this.providerService = providerService;
    }

    /**
     * 获取服务商配置列表
     */
    @GetMapping("/list")
    public Result<List<ProviderConfig>> getProviderList() {
        return Result.success(providerService.list());
    }

    /**
     * 获取单个服务商配置信息
     */
    @GetMapping("/{providerId}")
    public Result<ProviderConfig> getModelInfo(@PathVariable Integer providerId) {
        return Result.success(providerService.getById(providerId));
    }

    /**
     * 服务商配置添加
     */
    @PostMapping("/add")
    public Result<Void> addSystemPrompts(@RequestBody @Valid ProviderConfig providerConfig) {
        providerService.save(providerConfig);
        return Result.success();
    }

    /**
     * 服务商配置修改
     */
    @PostMapping("/update")
    public Result<Void> updateSystemPrompts(@RequestBody @Valid ProviderConfig providerConfig) {
        providerService.updateById(providerConfig);
        return Result.success();
    }

    /**
     * 服务商配置删除
     */
    @DeleteMapping("/{id}")
    public Result<Void> deleteSystemPrompts(@PathVariable @NotNull(message = "id不能为空") Integer id) {
        providerService.canDelete(id);
        return Result.success();
    }

}
